home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Demos / Extend 3.0 Demo / Demo Libraries / Demo Generic Lib / Demo Generic Lib.rsrc / MODL_30432_ReadOut < prev    next >
Encoding:
Text File  |  1994-06-22  |  3.7 KB  |  173 lines

  1. real    timeArray[];
  2. integer    oldTicks, oldWait, isConnected, duringSim;
  3. integer messageIn, DiscreteModel, dialogIsOpen;
  4.  
  5. **    This block displays the value at its input connector during 
  6. **  the simulation run.
  7. **
  8. **    Copyright © 1989-1994 by Imagine That,Inc.
  9. **    All Rights Reserved.
  10. **    Extend Generic Library, ReadOut block; J. Steven Lamperti 7/90
  11. **        modified
  12. **                1/7/92      JSL Extensively mnodified for V2.0
  13. **                11/23/92 JSL fix for generic blocks in discrete models
  14. **                6/24/93  JSL don't calc when animation off and open false
  15. **                6/28/93  JSL added dialogIsOpen
  16. **                1/17/93  JSL added duringSim
  17. **                2/15/94  DJK modified trace and report
  18. **                3/10/94  DJK added block label to report & trace
  19. **                3/23/94  DJK removed code that prevented value from updating if block was not open or animation was not on.
  20. **                4/6/94  JSL uncommented !open !animationOn !dialogIsOpen Return,
  21. **                            with extra if (isConnected) before it.
  22. **                4/6/94  JSL added initialization of oldTicks in several places
  23. **
  24.  
  25. procedure calc()
  26. {
  27.     if (isConnected)
  28.         Value = valueIn;
  29.  
  30.     if (!open and !animationOn and !dialogIsOpen)
  31.         return;
  32.  
  33.     if (isConnected)
  34.         {
  35.         Value = valueIn;
  36.  
  37.         if (animationOn)
  38.             {
  39.             animationText(1, value);
  40.             animationShow(1);
  41.             }
  42.         else if (open && !dialogIsOpen)
  43.             OpenDialogBox();
  44.         
  45.         oldWait = tickCount()-oldTicks;
  46.         if (oldWait < ticks)
  47.             WaitNTicks(ticks-oldWait);
  48.         
  49.         oldTicks = tickCount();
  50.         }
  51.  
  52.     ** sysGlobal2 is the file reference number for the DEBUG TRACE
  53.     if( sysGlobal2 != 0.0 )  ** 0 is error, check for open file for TRACE
  54.         {
  55. // template for report:      |BLOCK NAME *****************|block number |BLOCK NUMBER*******
  56.         fileWrite(sysGlobal2,"ReadOut                      block number "+(MyBlockNumber())+".  Current Time:"+currentTime+".","",True);
  57.         if(getBlockLabel(myBlockNumber()) != "")
  58.             fileWrite(sysGlobal2,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
  59.         fileWrite(sysGlobal2,"     Input = "+valueIn,"",True);
  60.         fileWrite(sysGlobal2," ","",True);
  61.         }
  62. }
  63.  
  64.  
  65. // on valueIn is a message handler that is only used by this block when the
  66. // block is used in Discrete Event models.
  67.  
  68. on valueIn
  69. {
  70.     messageIn = TRUE;
  71.     calc();
  72. }
  73.  
  74.  
  75. on dialogOpen
  76. {
  77.     oldTicks = 0;
  78.     calc();
  79.     dialogIsOpen = TRUE;
  80. }
  81.  
  82.  
  83. on openModel 
  84. {
  85.     oldTicks = 0;
  86. }
  87.  
  88.  
  89. on dialogClose
  90. {
  91.     dialogIsOpen = FALSE;
  92.     if (duringSim)
  93.         open = FALSE;
  94. }
  95.  
  96.  
  97. ** This message occurs for each step in the simulation.
  98. on simulate
  99. {
  100.     if (messageIn)    // Discrete models.  We've gotten a message, so no sim messages.
  101.         {
  102.         GetSimulateMsgs(FALSE);
  103.         return;
  104.         }
  105.  
  106.     if (DiscreteModel)
  107.         sendMsgToOutputs(valueIn);
  108.     calc();
  109. }
  110.  
  111.  
  112. ** If the dialog data is inconsistent for simulation, abort.
  113. on checkdata
  114. {
  115.     messageIn     = FALSE;
  116.     isConnected = valueIn;    ** true if connected
  117.  
  118.     if (animationOn)
  119.         {
  120.         AnimationText(1, "0");
  121.         AnimationShow(1);
  122.         }
  123.     else
  124.         AnimationHide(1, FALSE);
  125.         
  126.     if (NoValue(ticks) || ticks < 0)
  127.         ticks = 0;
  128. }
  129.  
  130.  
  131. on createBlock
  132. {
  133.     oldTicks      = 0;
  134.     open         = TRUE;
  135.     ticks         = 2;
  136.     messageIn     = FALSE;
  137.     dialogIsOpen = FALSE;
  138. }
  139.  
  140.  
  141. ** Initialize any simulation variables.
  142. on initsim
  143. {
  144.     Value        = BLANK;
  145.     oldTicks    = 0;
  146.  
  147.     DiscreteModel = getPassedArray(sysGlobal0, timeArray);
  148.     duringSim     = TRUE;
  149. }
  150.  
  151.  
  152. on abortSim
  153. {
  154.     duringSim = FALSE;
  155. }
  156.  
  157.  
  158. on endSim
  159. {
  160.     duringSim = FALSE;
  161.     if (isConnected)
  162.         Value = valueIn;
  163.  
  164.     ** sysGlobal1 is the file reference number for the TEXT REPORT
  165.     if( sysGlobal1 != 0.0 )  ** 0 is error, check for open file for REPORT
  166.         {
  167. // template for report:      |BLOCK NAME *****************|block number |BLOCK NUMBER*******
  168.         fileWrite(sysGlobal1,"ReadOut                      block number "+MyBlockNumber(),"",True);
  169.         if(getBlockLabel(myBlockNumber()) != "")
  170.             fileWrite(sysGlobal1,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
  171.         fileWrite(sysGlobal1," ","",True);
  172.         }
  173. }